package net.cmbt.okframe.okupgrade;

import android.app.AlertDialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import net.cmbt.okframe.R;


/**
 * Created by LG on 2019/3/15.
 */

public class AppleDialog extends AlertDialog.Builder {
    Context context;
    private TextView tile_dilog;
    private TextView content_dilog;
    private TextView cancle;
    private TextView sure;
    private TextView cancle1;
    private TextView sure1;
    private AlertDialog show;

    public AppleDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    public AppleDialog editDlalog(String title_tv, String content_tv, final String cancle_tv, String sure_tv, final DialogListener dialogListener) {
        View view = View.inflate(context, R.layout.dialog_yx, null);

        tile_dilog = (TextView) view.findViewById(R.id.tile_dilog);
        content_dilog = (TextView) view.findViewById(R.id.content_dilog);
        cancle1 = (TextView) view.findViewById(R.id.cancle);
        sure1 = (TextView) view.findViewById(R.id.sure);


        if (cancle_tv.isEmpty()) {
            cancle1.setVisibility(View.GONE);
        } else {
            cancle1.setVisibility(View.VISIBLE);
        }

        tile_dilog.setText(title_tv);
        content_dilog.setText(content_tv);
        cancle1.setText(cancle_tv);
        sure1.setText(sure_tv);
        this.setView(view);
        show = this.show();
        final Window dialogWindow = show.getWindow();
        dialogWindow.setWindowAnimations(R.style.mainfstyle);

        cancle1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogListener.cancleListener();
                show.dismiss();
            }
        });

        sure1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogListener.sureListener();
                show.dismiss();
            }
        });


        return this;

    }


    public interface DialogListener {
        void sureListener();

        void cancleListener();
    }

}
